package com.baibei.order.bill.deliveryquery;

import android.content.Context;

import com.baibei.basic.BasicPresenterImpl;
import com.baibei.ebec.sdk.ApiFactory;
import com.baibei.ebec.sdk.IOrderApi;
import com.baibei.model.DeliveryQueryInfo;
import com.baibei.sdk.ApiDefaultObserver;

import java.util.List;

/**
 * 表现实现类
 * Created by shenminjie on 2017/8/25.
 * mail:shenminjie@100bei.com
 */

public class DeliveryQueryPresenterImpl extends BasicPresenterImpl<DeliveryQueryContract.DeliveryQueryView> implements DeliveryQueryContract.Presenter {

    private IOrderApi mOrderApi;

    public DeliveryQueryPresenterImpl(Context context, DeliveryQueryContract.DeliveryQueryView view) {
        super(context, view);
        mOrderApi = ApiFactory.getInstance().getOrderApi();
    }

    @Override
    public void start() {
        createObservable(mOrderApi.getDeliveryQueryInfos()).subscribe(new ApiDefaultObserver<List<DeliveryQueryInfo>>() {
            @Override
            protected void onError(String s) {
                mView.hideRefreshLayout();
                mView.onLoadFailed(s);
            }

            @Override
            protected void accept(List<DeliveryQueryInfo> list) {
                mView.hideRefreshLayout();
                mView.onLoadSuccess(list);
            }
        });
    }
}
